package com.ljdemo.lrecorder.activity

import android.media.MediaPlayer
import android.media.MediaPlayer.OnCompletionListener
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.View.OnClickListener
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.ljdemo.lrecorder.R
import com.ljdemo.lrecorder.utils.AlertUtil
import com.ljdemo.lrecorder.view.FullScreenVideoView

class VideoPlayerActivity : AppCompatActivity() {

    private lateinit var vv:FullScreenVideoView
    private lateinit var playBtn: Button
    private lateinit var fileFullName:String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_video_player)

        initView()
        init()
    }

    private fun initView(){
        vv=findViewById(R.id.play_vv)
        vv.setOnCompletionListener(object : OnCompletionListener{
            override fun onCompletion(p0: MediaPlayer?) {
                // 播放完成
                playBtn.visibility=View.VISIBLE
            }

        })

        playBtn=findViewById(R.id.play_btn)
        playBtn.setOnClickListener {
            vv.requestFocus()
            vv.start()
            playBtn.visibility = View.GONE
        }
    }

    private fun init(){
        fileFullName = intent.getStringExtra("file")!!
        if (fileFullName == "" || fileFullName==null){
            AlertUtil.showCenterToast(this,"没有可播放的文件")
            Log.e("播放页","获取的文件名为空")
            return
        }
        vv.setVideoURI(Uri.parse(fileFullName))
        vv.requestFocus()
        vv.start()
    }

}